def is_prime(x):
    for i in range(2, (x//2)+1):
        if x % i == 0:
            return False
    return True


n = input()
if len(n) != 4:
    print(0)
    exit()
numbers = [int(n[0]), int(n[1]), int(n[2]), int(n[3]),
           int(n), int(n[0:2]), int(n[0:3]), int(n[0:4]),
           int(n[1:3]), int(n[1:4]), int(n[2:4])]
res = []
for i in numbers:
    if is_prime(i):
        res.append(i)
if len(res) > 0:
    print(max(res))
else:
    print(0)
